//
//  HomeTableViewCell.m
//  XTXOneToOne
//
//  Created by Canny on 2018/10/29.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "HomeTableViewCell.h"
@interface HomeTableViewCell ()


@property (nonatomic,strong)UILabel * lab_name1;
@property (nonatomic,strong)UILabel * lab_name2;

@property (nonatomic,strong)UILabel * lab_price1;
@property (nonatomic,strong)UILabel * lab_price2;

@property (nonatomic,strong)UILabel * lab_margin;

@end

@implementation HomeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self initView];
    }
    return self;
}

- (void)initView{
    
    self.backgroundColor=[UIColor whiteColor];
    
    _lab_name1 =[[UILabel alloc]init];
    _lab_name1.textColor=RGB(30, 63, 89);
    _lab_name1.font=[UIFont systemFontOfSize:14];
    _lab_name1.text =@"加载中...";
    _lab_name1.textAlignment=NSTextAlignmentLeft;
    [self  addSubview:_lab_name1];
    
    [_lab_name1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(0);
       make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(35);
        
    }];
    
    _lab_name2 =[[UILabel alloc]init];
    _lab_name2.textColor=RGB(131, 151, 167);
    _lab_name2.font=[UIFont systemFontOfSize:12];
    _lab_name2.text =@"加载中...";
    _lab_name2.textAlignment=NSTextAlignmentLeft;
    [self  addSubview:_lab_name2];
    
    [_lab_name2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(30);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(30);
        
    }];
    
    _lab_price1 =[[UILabel alloc]init];
    _lab_price1.textColor=RGB(30, 63, 89);
    _lab_price1.font=[UIFont systemFontOfSize:14];
    _lab_price1.text =@"加载中...";
    _lab_price1.textAlignment=NSTextAlignmentLeft;
    [self  addSubview:_lab_price1];
    
    [_lab_price1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(0);
        make.left.equalTo(self.mas_left).offset(G_SCREENWIDTH*0.3);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(35);
        
    }];
    
    _lab_price2 =[[UILabel alloc]init];
    _lab_price2.textColor=RGB(131, 151, 167);
    _lab_price2.font=[UIFont systemFontOfSize:12];
    _lab_price2.text =@"加载中...";
    _lab_price2.textAlignment=NSTextAlignmentLeft;
    [self  addSubview:_lab_price2];
    
    [_lab_price2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(30);
        make.left.equalTo(self.mas_left).offset(G_SCREENWIDTH*0.3);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(30);
        
    }];
    
    
    
    _lab_margin =[[UILabel alloc]init];
    _lab_margin.textColor=RGB(255, 255, 255);
    _lab_margin.font=[UIFont systemFontOfSize:12];
    _lab_margin.text =@"加载中...";
    _lab_margin.textAlignment=NSTextAlignmentCenter;
    [self  addSubview:_lab_margin];
    _lab_margin.backgroundColor=RGB(4, 192, 135);
    [_lab_margin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.right.equalTo(self.mas_right).offset(-15);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(30);
        
    }];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setDataSource:(HomeBaseTabCellModel *)dataSource{
    _dataSource = dataSource;
    
    //1.基础货币缩写/计价货币缩写  2.price    浮点型    最新成交价    3.margin    浮点型    涨跌幅度
    //1.24H volume    浮点型    成交总量 2.quote_price_cnyXprice
    
    
    _lab_name1.text=[NSString stringWithFormat:@"%@/%@",dataSource.base_symbol,dataSource.quote_symbol];;
    _lab_name2.text = [NSString stringWithFormat:@"24H %@",[self GetStr:dataSource.volume]];
    
    _lab_price1.text = [self GetStr:dataSource.price];
    _lab_price2.text=[NSString stringWithFormat:@"≈%.4f",[dataSource.price doubleValue]*[dataSource.quote_price_cny doubleValue]];
    
    _lab_margin.text=[NSString stringWithFormat:@"%@%%",[self GetStr:dataSource.margin]];
    
}

-(NSString *)GetStr:(NSString *)str{
    NSString * s = [NSString stringWithFormat:@"%@",str];
    if ([s containsString:@"null"]) {
        return @"0";
    }
    return s;
}

-(UILabel *)GetAdaptiveLable:(CGRect)rect AndText:(NSString *)contentStr andFont:(CGFloat)font  andTextColor:(UIColor *)textColor andTextAlignment:(NSTextAlignment)textAlignment;
{
    
    
    UILabel *contentLbl = [[UILabel alloc] initWithFrame:rect];
    contentLbl.text = contentStr;
    contentLbl.numberOfLines = 0;
    contentLbl.textAlignment = textAlignment;
    contentLbl.font = [UIFont systemFontOfSize:font];
    contentLbl.textColor=textColor;
    contentLbl.clipsToBounds=YES;
    
    return contentLbl;
}


+(CGFloat)computeHeight:(id)info{
    
    return 65;
    
}

@end


















